const cfg=require("../config/config");
const jwt=require("jsonwebtoken");
const jwtMiddleWare=(req,res,next)=>{
    if(!req.headers.authorization){
        next();
        return;
    }
    jwt.verify(req.headers.authorization,cfg.jwtSecret,(err,data)=>{
        if(err){
            console.log(err);
            res.send({code:4001,msg:"凭证过期或校验失败，请重新登录",data:null});
            return;
        }
        req.user=data;
        next();
    });
}
module.exports=jwtMiddleWare;
